package com.elink.enginerring.common;

/**
 * 错误类型,0为正常处理返回,1**为客户端错误,2**为服务器错误(具体错误自定义,如101为请求参数错误)
 * @author admin
 * 
 */
public enum ErrorType{
	SUCCESS							(0, "success"),
	CLIENT_ERROR					(1, "客户端未知错误"),
	SERVER_ERROR					(2, "服务器未知错误"),
	NEED_LOGIN						(-1, "请重新登录"),
	
	REQUEST_PARAMS_ERROR			                   (101, "请求参数不合法"),
	AUTHORITY_ERROR                                          (102, "没有操作权限"),
	SESSION_TIMEOUT_ERROR		                         (103, "session已超时"),
	REQUESTED_DATA_NOT_EXIST_ERROR	             (104, "请求的数据不存在"),
	LOGIN_ERROR                                                   (105, "手机号或密码错误"),
	PHONE_HAS_REGISTERED_ERROR                       (106, "手机号已注册"),
	DATE_PATTERN_ERROR    			                        (108, "日期格式错误"),
	PASSWORD_ERROR    				                        (109, "密码错误"),
	DICT_ERROR    				                                    (110, "该词条已存在，请您换其他的词条"),
	FILE_DOWNLOAD_ERROR    				                (111, "文件不存在或者下载失败"),

	
	DATABASE_ERROR                  (201, "数据库操作出错"),
	HANDLE_FILE_ERROR			    (203, "服务器处理文件出错");

	
	
	private int code;
	private String msg;

	public int getCode() {
		return code;
	}

	public String getMsg() {
		return msg;
	}

	private ErrorType(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	/**
	 * 根据code获取到msg
	 * @param code
	 * @return
	 */
	public static String getMsgByCode(int code){
		for(ErrorType e:ErrorType.values()){
			if(e.getCode()==code){
				return e.getMsg();
			}
		}
		return null;
	}
}